package dal;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

import com.google.gson.Gson;

import dal.datastore.IDataStoreConfig;
import dto.AuthenticationDTO;

public class InitializeDAO implements IDataStoreConfig {
	public void initialize() throws IOException {
		// 1. Create a json file to store databases structures.
		FileWriter fw = new FileWriter(new File(dbsPath));
		BufferedWriter bf = new BufferedWriter(fw);
		bf.write("[]");
		bf.close();
		fw.close();

		// 2. Create a json file to store authentication information.
		// and add a root accout
		Collection<Object> collection = new ArrayList<>();
		collection.add(new AuthenticationDTO("root", ""));

		Gson gson = new Gson();
		String json = gson.toJson(collection);

		fw = new FileWriter(new File(AUTH_FILE));
		bf = new BufferedWriter(fw);
		bf.write(json);
		bf.close();
		fw.close();

	}

}
